@extends('admin/index')
@section('name')
    <h1><span class="label label-default"> 编辑 </span></h1>
    <hr>

    <div class="container">
        <div class="row">
            <div class="col-md-4 col-md-offset-4">
                <form class="form-horizontal" action="{{url('adm/adm/add')}}" name="ckname" >
                    <div class="form-group">
                        <label for="inputEmail3" class="col-sm-2 control-label">分类名:</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" name="name" placeholder="name" onblur="checkname()">
                            <p id="p" style="display: none">此分类名已存在喔~</p>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputPassword3" class="col-sm-2 control-label">Pid</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" name="pid" readonly value="0">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputPassword3" class="col-sm-2 control-label">path</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" name="path" value="0," readonly>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputPassword3" class="col-sm-2 control-label">是否隐藏</label>
                        <div class="col-sm-10">
                            <label class="radio-inline">
                                <input type="radio" name="display" value="0"> no
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="display" value="1" checked> yes
                            </label>
                        </div>
                    </div>


                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <button type="submit" class="btn btn-default">提交</button>
                        </div>
                    </div>

                </form>
            </div>
        </div>
    </div>


    <script>


        //用户名验证
        function checkname() {

            var ckname = document.ckname.name.value;
            //var p = document.getElementById('p');
            if (ckname == '') {

                console.log('触发');

            }else{

                $.ajax({
                    type: 'get',
                    url: "{{url('adm/class/ajax')}}/" + ckname,
                    success: function (data) {
                        if (data == 1) {
                            p.style.color = 'red';
                            p.style.display = 'block';
                        }

                        if(data == 2) {

                            p.style.display = 'none';
                        }

                        console.log(data);

                    },
                    error: function (xhr, type) {
                        alert('Ajax error!');
                    }

                })


            }


 }
    </script>





@endsection
